package uw10.app.data;

public class GraphData
{
	public int length;
	public long[] time;
	public double[] value;
	
	public GraphData(int length, long[] time, double[] value)
	{
		this.length = length;
		this.time = time;
		this.value = value;
	}
	
	public double getValue(long t)
	{
		int i = 0;
		while (i < length && time[i] < t) i++;
		
		if (i == 0) return time[0];
		if (i == length) return time[length - 1];
		
		double s = ((double)(time[i] - t)) / (time[i] - time[i - 1]);
		return value[i] * (1 - s) + value[i - 1] * s;
	}
}
